﻿using System;
using filmquiz.Src.DatabaseAccess;
using filmquiz.Src.Ftp;
using MySql.Data.MySqlClient;

namespace filmquiz.Src
{
    public class Statics
    {
        private static Statics instance = null;

        private string imageBaseUrl = "http://images.thefilberts.dk/";
        private static string databaseUrl = "mysql9.unoeuro.com";
        private static string databaseScheme = "thefilberts_dk_db";
        private static string databaseUser = "thefilberts_dk";
        private static string databasePassword = "Hilbert1";
        private string smtpServer = "smtp.unoeuro.com";
        private string emailSender = "daniel@thefilberts.dk";
        private int charsInGeneratedPassword = 6;
        private int currentRound;
        private string ftpUrl = "ftp://thefilberts.dk/images";
        private string ftpPassword = "Hilbert1";
        private string ftpUserName = "thefilberts.dk";

        private Statics()
        {
            getCurrentRoundFromDataBase();
        }

        public static Statics getInstance()
        {
            if (instance == null)
            {
                instance = new Statics();
            }
            return instance;
        }

        public static string getDataBaseUrl()
        {
            return databaseUrl;
        }

        public static string getDataBaseScheme()
        {
            return databaseScheme;
        }

        public static string getDataBaseUser()
        {
            return databaseUser;
        }

        public static string getDataBasePassword()
        {
            return databasePassword;
        }

        public int getNumberOfQuestions()
        {
            return FtpHelper.getInstance().getNumberOfImages(currentRound);
        }

        public string getImageBaseUrl()
        {
            return imageBaseUrl;
        }

        public string getSmtpServer()
        {
            return smtpServer;
        }

        public string getEmailSender()
        {
            return emailSender;
        }

        public int getCurrentRound()
        {
            return currentRound;
        }

        public int getCharsInGeneratedPasswords()
        {
            return charsInGeneratedPassword;
        }

        public string getFtpUrl()
        {
            return ftpUrl;
        }

        public string getFtpPassword()
        {
            return ftpPassword;
        }

        public string getFtpUserName()
        {
            return ftpUserName;
        }

        public void getCurrentRoundFromDataBase()
        {
            string query = "select propertyValue from properties where idproperties = 'currentRound';";
            MySqlDataReader reader = DbAcces.getInstance().Select(query);

            reader.Read();

            int result = Int32.Parse(reader.GetString(0));

            DbAcces.getInstance().CloseConnection();
            reader.Close();

            currentRound = result;
        }
    }
}